'''
Created on 2011-10-30

@author: tony.li.fly@gmail.com
'''
from xyh.oa.models import PackType
from django.http import HttpResponse
from django.utils import simplejson as json
def listall(request):
    result = []
    for c in PackType.objects.order_by('code').all():
        result.append({'id':c.id, 'code':c.code, 'name':c.name})
    return HttpResponse(json.dumps(result))


def delPackType(request, packType_id):
    packType = PackType.objects.get(pk=packType_id)
    packType.delete()
    return HttpResponse()
    
def addPackType(request):
    packType = PackType(code=request.POST['code'], name=request.POST['name'])
    packType.save()
    return HttpResponse()

def updatePackType(request):
    packType = PackType.objects.get(pk=request.POST['id'])
    packType.name = request.POST['name']
    packType.code = request.POST['code']
    packType.save()
    return HttpResponse()
